<template>
  <el-dialog
     v-drag
    :title="!dataForm.fileId ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :inline="true" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
<el-form-item label="收货单ID" prop="receiveId">
  <el-input size="mini"  v-model="dataForm.receiveId" placeholder="收货单ID" clearable></el-input>
</el-form-item>
<el-form-item label="附件类别：1收货单2发票" prop="fileType">
  <el-input size="mini"  v-model="dataForm.fileType" placeholder="附件类别：1收货单2发票" clearable></el-input>
</el-form-item>
<el-form-item label="附件名称" prop="fileName">
  <el-input size="mini"  v-model="dataForm.fileName" placeholder="附件名称" clearable></el-input>
</el-form-item>
<el-form-item label="附件地址" prop="filePath">
  <el-input size="mini"  v-model="dataForm.filePath" placeholder="附件地址" clearable></el-input>
</el-form-item>
<el-form-item label="门店id" prop="storeId">
  <el-input size="mini"  v-model="dataForm.storeId" placeholder="门店id" clearable></el-input>
</el-form-item>
<el-form-item label="门店名称" prop="storeName">
  <el-input size="mini"  v-model="dataForm.storeName" placeholder="门店名称" clearable></el-input>
</el-form-item>
<el-form-item label="门店编码" prop="storeCode">
  <el-input size="mini"  v-model="dataForm.storeCode" placeholder="门店编码" clearable></el-input>
</el-form-item>
<el-form-item label="创建时间" prop="createTime">
  <el-input size="mini"  v-model="dataForm.createTime" placeholder="创建时间" clearable></el-input>
</el-form-item>
<el-form-item label="修改时间" prop="updateTime">
  <el-input size="mini"  v-model="dataForm.updateTime" placeholder="修改时间" clearable></el-input>
</el-form-item>
<el-form-item label="创建人" prop="createUsername">
  <el-input size="mini"  v-model="dataForm.createUsername" placeholder="创建人" clearable></el-input>
</el-form-item>
<el-form-item label="创建人id" prop="createUserId">
  <el-input size="mini"  v-model="dataForm.createUserId" placeholder="创建人id" clearable></el-input>
</el-form-item>
<el-form-item label="修改人" prop="updateUsername">
  <el-input size="mini"  v-model="dataForm.updateUsername" placeholder="修改人" clearable></el-input>
</el-form-item>
<el-form-item label="修改人id" prop="updateUserId">
  <el-input size="mini"  v-model="dataForm.updateUserId" placeholder="修改人id" clearable></el-input>
</el-form-item>
<el-form-item label="是否可用 1:是" prop="status">
  <el-input size="mini"  v-model="dataForm.status" placeholder="是否可用 1:是" clearable></el-input>
</el-form-item>
<el-form-item label="是否删除 1:是" prop="isDeleted">
  <el-input size="mini"  v-model="dataForm.isDeleted" placeholder="是否删除 1:是" clearable></el-input>
</el-form-item>
<el-form-item label="备注" prop="remark">
  <el-input size="mini"  v-model="dataForm.remark" placeholder="备注" clearable></el-input>
</el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button size="mini" @click="visible = false">取消</el-button>
      <el-button size="mini" type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          fileId: 0,
          receiveId: '',
          fileType: '',
          fileName: '',
          filePath: '',
          storeId: '',
          storeName: '',
          storeCode: '',
          createTime: '',
          updateTime: '',
          createUsername: '',
          createUserId: '',
          updateUsername: '',
          updateUserId: '',
          status: '',
          isDeleted: '',
          remark: ''
        },
        dataRule: {
          receiveId: [
            { required: true, message: '收货单ID不能为空', trigger: 'blur' }
          ],
          fileType: [
            { required: true, message: '附件类别：1收货单2发票不能为空', trigger: 'blur' }
          ],
          fileName: [
            { required: true, message: '附件名称不能为空', trigger: 'blur' }
          ],
          filePath: [
            { required: true, message: '附件地址不能为空', trigger: 'blur' }
          ],
          storeId: [
            { required: true, message: '门店id不能为空', trigger: 'blur' }
          ],
          storeName: [
            { required: true, message: '门店名称不能为空', trigger: 'blur' }
          ],
          storeCode: [
            { required: true, message: '门店编码不能为空', trigger: 'blur' }
          ],
          createTime: [
            { required: true, message: '创建时间不能为空', trigger: 'blur' }
          ],
          updateTime: [
            { required: true, message: '修改时间不能为空', trigger: 'blur' }
          ],
          createUsername: [
            { required: true, message: '创建人不能为空', trigger: 'blur' }
          ],
          createUserId: [
            { required: true, message: '创建人id不能为空', trigger: 'blur' }
          ],
          updateUsername: [
            { required: true, message: '修改人不能为空', trigger: 'blur' }
          ],
          updateUserId: [
            { required: true, message: '修改人id不能为空', trigger: 'blur' }
          ],
          status: [
            { required: true, message: '是否可用 1:是不能为空', trigger: 'blur' }
          ],
          isDeleted: [
            { required: true, message: '是否删除 1:是不能为空', trigger: 'blur' }
          ],
          remark: [
            { required: true, message: '备注不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.fileId = id || 0
        this.visible = true
        this.$nextTick(async () => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.fileId) {
            const res = await this.$http({
              url: `/purchase/purchasereceiveorderfile/info/${this.dataForm.fileId}`,
              method: 'get',
              params: this.$http.adornParams()
            })
                let data = res.data
                if (data && data.code === 0) {
                    this.dataForm = data.purchaseReceiveOrderFile
                }
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate(async (valid) => {
          if (valid) {
            const res = await this.$http({
              url:`/purchase/purchasereceiveorderfile/${!this.dataForm.fileId ? 'save' : 'update'}`,
              method: 'post',
             data: this.$http.adornData( this.dataForm)
            })
            let data = res.data
            if (data && data.code === 0) {
                this.$message({
                        message: '操作成功',
                        type: 'success',
                        duration: 1500,
                        onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                }
            })
            } else {
                this.$message.error(data.msg)
            }
          }
        })
      }
    }
  }
</script>
